import React from "react";
import { NavBar } from 'antd-mobile'
import PropTypes from 'prop-types'
import { useNavigate,useLocation,useSearchParams } from 'react-router-dom'
import './NavBarAgain.less'

const NavBarAgain = (props)=>{
    const {title} = props
    const Navigate = useNavigate(), location = useLocation(), [usp] = useSearchParams()

    const handleBack = ()=>{
        const to = usp.get('to')
        if(location.pathname === '/login' && /^\/detail\/\d+$/.test(to)){
            Navigate(to,{ replace:true })
            return;
        }
        Navigate(-1)
    }
    return <NavBar onBack={handleBack} className="navbar-again-box">
        {title}
    </NavBar>
}
NavBarAgain.defaultProps = {
    title:'个人中心'
}
NavBarAgain.propTypes = {
    title:PropTypes.string
}

export default NavBarAgain